// ///////////////////////////// MIT License //////////////////////////////////// //
//                                                                                //
// Copyright (c) 2010 David Zsolt Manrique                                        //
//                    david.zsolt.manrique@gmail.com                              //
//                                                                                //
// Permission is hereby granted, free of charge, to any person obtaining a copy   //
// of this software and associated documentation files (the "Software"), to deal  //
// in the Software without restriction, including without limitation the rights   //
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell      //
// copies of the Software, and to permit persons to whom the Software is          //
// furnished to do so, subject to the following conditions:                       //
//                                                                                //
// The above copyright notice and this permission notice shall be included in     //
// all copies or substantial portions of the Software.                            //
//                                                                                //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR     //
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,       //
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE    //
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER         //
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  //
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN      //
// THE SOFTWARE.                                                                  //
//                                                                                //
// ////////////////////////////////////////////////////////////////////////////// //

#include "hamiltonian.h"

using namespace std;


int main(int argc, char* argv[])
{
try
{
        cmd::arguments arg(argc,argv);
        cmd::switcharg<false> help(arg,"-h","--help", "print help message");

        cmd::vararg<double> tol(arg,"-tol","--tol"," X tolerance def.: 1e-5",1.0e-5);

//        cmd::switcharg<false> shinfo(arg,"-i","--info", "info about the file");

        cmd::switcharg<false> psearch(arg,"-d","--pattern-search", "diagonal pattern search");
 
        cmd::switcharg<false> pattern(arg,"-p","--pattern", "atom interaction pattern s,h");

        cmd::varargxx<int,int> pattern_h(arg,"-H","--h-pattern","hamiltonain matrix pattern <drow> <dcol>",1,1);
        cmd::varargxx<int,int> pattern_s(arg,"-S","--s-pattern","overlap matrix pattern <drow> <dcol>",1,1);

        cmd::switcharg<false> gollum(arg,"-g","--gollum", "hamiltonian file in gollum format");

//        cmd::switcharg<false> symmetrize(arg,"-s","--sym", "symetrize hamiltonian file before calculation");

        cmd::posarg<std::string> ham_fn(arg,"hamiltonain input file name", "");

        if(*help)
        {
                arg.print_help(std::cout,"shinfo");
                std::cout << "version 0.95b" << std::endl;
                std::cout << "Copyright (c) 2010 David Zsolt Manrique (david.zsolt.manrique@gmail.com)"  << std::endl;
                return EXIT_SUCCESS;
        }
        
        if(!~ham_fn) throw std::runtime_error("Give hamiltonian file!");

        blockSH sh;
        if(!*gollum) load(*ham_fn,sh); else load_gollum(*ham_fn,sh);

        std::cout << "Atoms : " << sh.n << std::endl;
        std::cout << "S rows x cols : " << sh.S.rows() << "x" << sh.S.cols() << std::endl;
        std::cout << "H rows x cols : " << sh.H.rows() << "x" << sh.H.cols() << std::endl;
        std::cout << "Antisym norm ||S-S'||/2 : " << std::scientific << 0.5*(sh.S-sh.S.adjoint()).norm() << std::endl;
        std::cout << "Antisym norm ||H-H'||/2 : " << std::scientific << 0.5*(sh.H-sh.H.adjoint()).norm() << std::endl;
        std::cout << "Fermi energy : " << std::fixed << sh.ef << std::endl;
        
        if(~pattern) sh.print_pattern(std::cout,*tol);
        
        if(~pattern_h) print_pattern(std::cout,sh.H,pattern_h.var1,pattern_h.var2,*tol);
        if(~pattern_s) print_pattern(std::cout,sh.S,pattern_s.var1,pattern_s.var2,*tol);
        

        
} catch(const char* message)
{
    std::cerr << message << std::endl;
    std::cerr << "(exit)" << std::endl;
    return EXIT_FAILURE;
}
catch(const std::exception & e)
{
    std::cerr << e.what() << std::endl;
    std::cerr << "(exit)" << std::endl;
    return EXIT_FAILURE;
}
    return EXIT_SUCCESS;
            

}

